#include <stdlib.h>
#include <math.h>

// 点结构
typedef struct s_point
{
  double x;
  double y;
} t_point;

typedef struct s_test
{
  char *sentence; // 句子
  int nb_points; 
  t_point *points; // 点
  double *distances; // 两点距离，指针
} t_test;

// 增量字符串
char *increment_string(char *str, int n)
{
  for (int i = 0; str[i]; i++)
    // 每个字符做一次偏移
    str[i] = str[i] + n;
  return (str);
}

// 随机生成点集合
void generate_points(t_test *test, int nb)
{
  // calloc () 函数用来动态地分配内存空间并初始化为 0
  // 其实就是初始化变量，为其分配内存空间
  t_point *points = calloc(nb + 1, sizeof(t_point));

  for (int i = 0; i < nb; i++)
  {
    points[i].x = rand();
    points[i].y = rand();
  }
  // 将结构地址赋值给指针
  test->points = points;
  test->nb_points = nb;
}

// 计算集合中点的距离
void distance_between_points(t_test *test)
{
  int nb = test->nb_points;
  // 创建变量空间
  double *distances = calloc(nb * nb + 1, sizeof(double));

  for (int i = 0; i < nb; i++)
    for (int j = 0; j < nb; j++)
      // sqrt 计算平方根
      distances[i * nb + j] = sqrt((test->points[j].x - test->points[i].x) * (test->points[j].x - test->points[i].x) + (test->points[j].y - test->points[i].y) * (test->points[j].y - test->points[i].y));
  test->distances = distances;
}